﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Farmacia.Entities;
using Microsoft.Practices.EnterpriseLibrary.Common.Configuration;
using Microsoft.Practices.EnterpriseLibrary.Data;

using System.Data;
using System.Data.Common;

using Microsoft.Practices.Unity;


namespace Farmacia.DataAccess
{
    public class ProveedorDAO:MasterDAEL,iProveedorDAO 
    {

        public List<Proveedor> GetAllFromProveedor()
        {
            var query = DataBase.ExecuteSprocAccessor<Proveedor>("GetAllFromProveedor");

            return query.ToList(); 
        }

        //public Proveedor GetFromProveedorByRuc(string ruc)
        //{

        //}

        public void RegistrarProveedor(Proveedor proveedor)
        {
            DbCommand command = DataBase.GetStoredProcCommand("RegistrarProveedor");

            DataBase.AddInParameter(command, "IdProveedor", DbType.Int32, proveedor.IdProveedor);
            DataBase.AddInParameter(command,"Ruc",DbType.String, proveedor.Ruc);
            DataBase.AddInParameter(command,"RazonSocial",DbType.String, proveedor.RazonSocial);
            DataBase.AddInParameter(command,"Direccion",DbType.String, proveedor.Direccion);
            DataBase.AddInParameter(command,"Telefono",DbType.String, proveedor.Telefono);
            DataBase.AddInParameter(command,"PersonaContacto",DbType.String, proveedor.PersonaContacto);
            DataBase.AddInParameter(command,"Ciudad",DbType.String, proveedor.Ciudad);
            DataBase.AddInParameter(command,"Email",DbType.String, proveedor.Email);
            DataBase.AddInParameter(command,"Movil",DbType.String, proveedor.Movil);

            DataBase.ExecuteNonQuery(command);

        }

        public void DeleteProveedor(int idProveedor)
        {
            DbCommand command = DataBase.GetStoredProcCommand("EliminarProveedor");

            DataBase.AddInParameter(command, "IdProveedor", DbType.Int32, idProveedor);
            
            DataBase.ExecuteNonQuery(command);
        }


        public Proveedor GetFromProveedorById(int id)
        {
            var query = DataBase.ExecuteSprocAccessor<Proveedor>("GetAllFromProveedorById", id);

            return query.SingleOrDefault(); 
        }


        public List<Proveedor> GetFromProveedorByRuc(string ruc)
        {
            var query = DataBase.ExecuteSprocAccessor<Proveedor>("GetFromProveedorByRuc", ruc);

            return query.ToList(); 
        }
    }
}

